package com.beaven.imserver.net.bean.api.account;

import com.beaven.imserver.net.bean.db.User;
import com.google.common.base.Strings;
import com.google.gson.annotations.Expose;

/**
 * author: Beaven
 * time: 2017/5/23 11:28
 */
public class UpdatePwdModel {

  @Expose
  private String oldPassword;

  @Expose
  private String newPassword;

  public String getOldPassword() {
    return oldPassword;
  }

  public void setOldPassword(String oldPassword) {
    this.oldPassword = oldPassword;
  }

  public String getNewPassword() {
    return newPassword;
  }

  public void setNewPassword(String newPassword) {
    this.newPassword = newPassword;
  }

  public static boolean check(UpdatePwdModel updatePwdModel) {
    return updatePwdModel != null && (!Strings.isNullOrEmpty(updatePwdModel.newPassword))
        && (!Strings.isNullOrEmpty(updatePwdModel.oldPassword));
  }

  public User updateToUser(User user) {
    if (!Strings.isNullOrEmpty(newPassword)) {
      user.setPassword(newPassword);
    }
    return user;
  }
}
